//
// Created by Administrator on 2024/3/26.
//
#include<bits/stdc++.h>

using namespace std;
using ll = long long;
//#define endl '\n'
int a[20], book[20], n = 8;

bool ok(int a[]) {
    for (int i = 0; i < n; i++) {
        for (int j = i + 1; j < n; j++) {
            //Qi(i,a[i]) Qj(j,a[j])

            if (abs(a[j] - a[i]) == (j - i)) {
                return false;
            }
        }
    }
    return true;
}

void dfs(int k) {
    if (k >= n) {
        if (ok(a)) {
            for (int i = 0; i < n; i++) {
                cout << a[i];
            }
            cout << endl;
            return;
        }
    }
    for (int i = 0; i < n; i++) {
        if (book[i] == 1)continue;//查表
        a[k] = i;
        book[i] = 1;//写入标记数组
        dfs(k + 1);
        book[i] = 0;//当我们访问完叶子结点后，必须要重置book[i]为未选择状态
    }


}


int main() {

    dfs(0);

    return 0;
}